package org.xhy.retryer.strategy;

import org.xhy.retryer.core.RetryerSupplier;
import org.xhy.retryer.lister.RetryerLister;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * @description:
 * @gitee: https://gitee.com/XhyQAQ
 * @copyright: B站: https://space.bilibili.com/152686439
 * @Author: Xhy
 * @CreateTime: 2024-04-29 21:37
 */
public abstract class  RetryerStrategy {

    protected int count;

    protected final long time;

    protected final TimeUnit timeUnit;

    public RetryerStrategy(int count, long time, TimeUnit timeUnit) {
        this.count = count;
        this.time = time;
        this.timeUnit = timeUnit;
    }

    protected RetryerLister retryerLister;

    public abstract void reset();

    abstract boolean exec();

    public boolean exec1(){
        final boolean result = exec();
        if (result){
            execRetryerLister();
        }
        return result;
    }
    void execRetryerLister(){
        if (null != retryerLister){
            retryerLister.exec(this);
        }
    }

    public void setRetryerLister(RetryerLister retryerLister){
        this.retryerLister = retryerLister;
    }

    public int getCount(){
        return count;
    }

    public long getTime(){
        return time;
    }

    public TimeUnit getTimeUnit(){
        return timeUnit;
    }
}
